<?php
Prado::using('Application.common.common');
class ContactUs extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->Master->pageHead->Title = $this->Application->Parameters["WEBSITE_TITLE"] . " | Contact Us";
		
		if (!$this->IsPostBack)
		{
		}
	}
	
	protected function btnSubmit_Clicked($sender, $param)
	{
		
		if ($this->IsValid)
		{			
			$emailer = $this->Application->getModule('mailer');
			$email = $emailer->createNewEmail("ContactUs");
			$email->HtmlContent->findControl("NAME")->Text = $this->txtName->SafeText;
			$email->HtmlContent->findControl("EMAIL")->Text = $this->txtEmail->SafeText;
			$email->HtmlContent->findControl("CONTACT")->Text = $this->txtContact->SafeText;
			$email->HtmlContent->findControl("SUBJECT")->Text = $this->ddlSubject->SelectedItem->Text;
			$email->HtmlContent->findControl("MESSAGE")->Text = $this->txtMessage->SafeText;

			$receiver = new TEmailAddress;
			$receiver->Field = TEmailAddressField::Receiver;
			$receiver->Address = $this->Application->Parameters["CONTACTUS_EMAIL"];
			$receiver->Name = $this->Application->Parameters["CONTACTUS_NAME"];
			$email->getEmailAddresses()->add($receiver);
					
			try
			{
				$emailer->send($email);
				$this->noticeMsg->Text = $this->Application->getModule('message')->translate("CONTACT_RECEIVED");
				$this->noticeMsg->Visible = true;
				$this->noticePanel->Visible = true;
				$this->mainPanel->Visible = false;
			}
			catch(TException $e)
			{
				$this->noticeMsg->Text = $this->Application->getModule('message')->translate("UNKNOWN_ERROR");
				$this->noticeMsg->Visible = true;
				$this->noticePanel->Visible = true;
				$this->resetPwdPanel->Visible = false;
			}			
		}		
	}
	
	protected function btnCancel_Clicked($sender, $param)
	{
		$this->Response->redirect($this->Service->ConstructUrl("Index"));
	}
}

?>